
package com.android.generator.translate;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;

import com.android.replace.StringUtils;
import com.android.replace.TextUtils;

public class GenerateTranslate {

    public static void replaceTab(String file) {
        if (TextUtils.isEmpty(file)) {
            return;
        }
        File sourceFile = new File(file);
        BufferedReader br = null;
        boolean success = false;
        HashMap<String, String> maps = new HashMap<>();
        HashMap<String, String> newMaps = new HashMap<>();
        try {
            br = new BufferedReader(new FileReader(sourceFile));
            String line;
            while ((line = br.readLine()) != null) {
                if (TextUtils.isEmpty(line)) {
                    continue;
                }
                line = line.trim();
                if(maps.containsKey(line)){
                    continue;
                }
                String newLine = StringUtils.replaceAllTab(line);
                newLine = line.replaceAll(" ", "_").replaceAll("-", "_");
                newLine = StringUtils.replaceAllSymbol(newLine);
                newLine = StringUtils.replaceAllTab(newLine);
                newLine = ("TRID_"+newLine).toUpperCase();
                System.out.println("public static final String "+newLine+" = "+"\""+line+"\";");
                maps.put(line, line);
                newMaps.put(newLine, newLine);
            }
            System.out.println();
            System.out.println();
            System.out.println("----------------------------------------------------");
            System.out.println();
            System.out.println();
            Iterator<String> iterator = newMaps.keySet().iterator();
            while (iterator.hasNext()) {
                String key = (String) iterator.next();
                System.out.println("getString(TranslateId."+key+")");
            }
            success = true;
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            success = false;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            success = false;
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

    }
    
    

    public static void main(String[] args) {
        replaceTab("C:\\Users\\yl1132\\Desktop\\translate.txt");
    }

}
